<?php

class UserInfosTable extends Zend_Db_Table_Abstract
{
	public function __construct($config = array())
	{
		$config['db'] = Zend_Registry::get('db');
		$config['name'] = 'user_infos';
		$config['primary'] = array('user_id', 'key');
		parent::__construct($config);
	}
	
	public function addUserInfo($user_id, $key, $value)
	{
		$logger = Zend_Registry::get('logger');
	
		try
		{	
			//$birthday_date = new Zend_Date($birthday, 'dd MMMM yyyy', 'en');
			//$birthday_sql = $birthday_date->toString(Zend_Date::ISO_8601);
			//$logger->debug("birthday_date=$birthday_date");
			//$logger->debug("birthday_sql={$birthday_sql}");
			
			$user_info_id = $this->insert(array(
								'user_id'=>$user_id, 
								'key'=>$key, 
								'value'=>$value
							));
							
			return $user_info_id;
		}
		catch (Exception $ex)
		{
			$this->logger->err("User info ({$user_id},{$key}) was not added. {$ex}");
			throw $ex;
		}
	}
	
	public function getAllInfo($user_id)
	{
		$user_info = array();
		
		$select = $this->select()->where('user_id = ?', $user_id);
		$user_info_rows = $this->fetchAll($select);
		
		foreach ($user_info_rows as $user_info_row)
			$user_info[$user_info_row['key']] = $user_info_row['value'];
		
		return $user_info;
	}
}
?>
